package com.feng.leetcode;

import java.util.Arrays;

/**
 * @author feng
 * @decrition
 * @date 2022/11/1822:56
 */
public class L891 {
    public static int sumSubseqWidths(int[] nums) {
        int[] copy = Arrays.copyOf(nums, nums.length);
        Arrays.sort(copy); // 112233

        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            int min = nums[i];
            int max = nums[i];
            for (int j = i + 1; j < nums.length; j++) {
                min = Math.min(min, nums[j]);
                max = Math.max(max, nums[j]);
                int result = max - min;
                sum += result;
                if (i != j - 1) {
                    sum += Math.abs(nums[i] - nums[j]);
                }
            }
        }
        return sum % 1000000007;
    }

    public static void main(String[] args) {
        int[] nums = {2,1,3};
        sumSubseqWidths(nums);
    }
}
